/*
 * Copyright (c) 2009, Servoy-stuff
 * 
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 * 
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 * http://www.fsf.org/licensing/licenses/lgpl.txt
 */
package net.stuff.servoy.plugins.listeners;

import java.beans.PropertyChangeEvent;
import java.util.Properties;

import javax.swing.Icon;
import javax.swing.ImageIcon;

import com.servoy.j2db.plugins.IClientPlugin;
import com.servoy.j2db.plugins.IClientPluginAccess;
import com.servoy.j2db.plugins.PluginException;
import com.servoy.j2db.preference.PreferencePanel;
import com.servoy.j2db.scripting.IScriptObject;
import com.servoy.j2db.util.Debug;

/**
 * 
 * @author Servoy-stuff
 * http://www.servoy-stuff.net/
 */
public class KeyListenersPlugin implements IClientPlugin {

	private IScriptObject provider;
	private IClientPluginAccess app;

	public Icon getImage() {
		java.net.URL iconUrl = this.getClass().getResource("images/Keyboard.png");
		if (iconUrl != null) {
			return new ImageIcon(iconUrl);
		} else {
			return null;
		}
	}

	public String getName() {
		return "keyListeners";
	}

	public PreferencePanel[] getPreferencePanels() {
		return null;
	}

	public IScriptObject getScriptObject() {
		if (provider == null) {
			boolean isWeb = false;
			if (app != null && app.getApplicationType() == IClientPluginAccess.WEB_CLIENT)
				isWeb = true;
			this.provider = new KeyListenersPluginProvider(getName(), isWeb);
		}
		return provider;
	}

	public void initialize(IClientPluginAccess app) throws PluginException {
		this.app = app;
		if (app.getApplicationType() == IClientPluginAccess.WEB_CLIENT) {
			Debug.error(getName()+" plugin is not web-client compatible: It will do nothing more!");
		}
	}

	public Properties getProperties() {
		Properties props = new Properties();
		props.put(DISPLAY_NAME, getName()); 
		return props;
	}

	public void load() throws PluginException {
		// ignore
	}

	public void unload() throws PluginException {
		this.provider = null;
		this.app = null;
	}

	public void propertyChange(PropertyChangeEvent evt) {
		// ignore
	}

}
